package com.fling.hero.state;

import com.badlogic.gdx.math.Vector2;
import com.fling.Locator;
import com.fling.entity.CollisionEntity;
import com.fling.objects.Hero;

public class FallingState extends HeroState {

	private Vector2 vel;

	public FallingState(Hero h) {
		super(h);
		type = STATE_TYPE.FALL_STATE;
	}

	@Override
	public void update(float delta) {
		tmp.set(vel);
		hero.getBody().setLinearVelocity(
				tmp.scl(Locator.getXGameSpeed() * Locator.getOverallGameSpeed() * delta, Locator.getYGameSpeed() * Locator.getOverallGameSpeed()
						* delta));

	}

	@Override
	public void newAction(INPUT input) {
		switch (input) {
		case CLIMB:
			hero.changeState(new ClimbingState(hero));
			exit();
			break;
		case FALL:
			break;
		case JUMP_RIGHT:
			if (!hero.isRightSide()) {
				hero.changeState(new FirstJumpState(hero, input));
			}
			break;
		case JUMP_LEFT:
			if (hero.isRightSide()) {
				hero.changeState(new FirstJumpState(hero, input));
			}
			break;
		default:
			exit();
			break;
		}
	}

	@Override
	public void enter() {
		vel = new Vector2(0, hero.FALLING_VEL);
		hero.setSprite(hero.getClimbSprite());
		hero.setFlipX(hero.isRightSide());
	}

	@Override
	public void exit() {
	}

	@Override
	public void collide(CollisionEntity otherBody) {
		if (otherBody.getType().equals(TYPE.BLOCK)) {
			hero.die();
		}

	}
}
